/**
 * Copyright (c) 2021 Coder League
 * All rights reserved.
 *
 * File：GoodPictureDaoImpl.java
 * History:
 *         2021年1月5日: Initially created, Chrise.
 */
package club.coderleague.cfss.dao.impl;

import java.util.List;

import club.coderleague.cfss.dao.extension.GoodPictureDaoExtension;
import club.coderleague.cfss.domain.beans.GoodPictureUpdateRequest;
import club.coderleague.cfss.domain.entities.Goodpictures;
import club.coderleague.cfss.domain.enums.EntityState;
import club.coderleague.cfss.domain.enums.PictureType;
import club.coderleague.data.jpa.id.support.SnowflakeV4;
import club.coderleague.data.jpa.repository.support.AbstractDataRepositoryExtension;

/**
 * 商品图片数据访问对象实现。
 * @author Chrise
 */
public class GoodPictureDaoImpl extends AbstractDataRepositoryExtension<Goodpictures, Long, SnowflakeV4> implements GoodPictureDaoExtension {
	/**
	 * @see club.coderleague.cfss.dao.extension.GoodPictureDaoExtension#queryCoverPictureForUpdate(long, java.lang.String)
	 */
	@Override
	public GoodPictureUpdateRequest queryCoverPictureForUpdate(long goodid, String picturepath) {
		String sql = "select entityid as pictureid, concat('" + picturepath + "', picturepath) as picturepath " 
			+ "from Goodpictures where goodid = ?0 and entitystate = ?1 and picturetype = ?2";
		return super.queryCustomBeanBySql(GoodPictureUpdateRequest.class, sql, goodid, EntityState.VALID.getValue(), PictureType.COVER.getValue());
	}
	
	/**
	 * @see club.coderleague.cfss.dao.extension.GoodPictureDaoExtension#queryOtherPictureForUpdate(long, java.lang.String)
	 */
	@Override
	public List<GoodPictureUpdateRequest> queryOtherPictureForUpdate(long goodid, String picturepath) {
		String sql = "select entityid as pictureid, concat('" + picturepath + "', picturepath) as picturepath " 
			+ "from Goodpictures where goodid = ?0 and entitystate = ?1 and picturetype = ?2";
		return super.queryCustomBeanListBySql(GoodPictureUpdateRequest.class, sql, goodid, EntityState.VALID.getValue(), PictureType.NORMAL.getValue());
	}
	
	/**
	 * @see club.coderleague.cfss.dao.extension.GoodPictureDaoExtension#queryGoodPictures(long, java.lang.String)
	 */
	@Override
	public List<String> queryGoodPictures(long goodid, String picturepath) {
		String sql = "select concat('" + picturepath + "', picturepath) as picturepath from Goodpictures where goodid = ?0 and entitystate = ?1 order by picturetype";
		return super.queryStringListBySql(sql, goodid, EntityState.VALID.getValue());
	}
}
